﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace StoneStorage
{
    public class Repository
    {
        public StoneStorageDataSet DSet
        {
            get;
            private set;
        }

        private StoneStorageDataSetTableAdapters.TableAdapterManager manager;

        public Repository()
        {
            CreateDataSet();
        }

        private void CreateDataSet()
        {
            this.DSet = new StoneStorageDataSet();
            this.manager = new StoneStorageDataSetTableAdapters.TableAdapterManager();

            var adapter6 = new StoneStorageDataSetTableAdapters.StoneDictionaryTableAdapter();
            this.manager.StoneDictionaryTableAdapter = adapter6;
            adapter6.Fill(DSet.StoneDictionary);

            var adapter5 = new StoneStorageDataSetTableAdapters.ProducerDictionaryTableAdapter();
            this.manager.ProducerDictionaryTableAdapter = adapter5;
            adapter5.Fill(DSet.ProducerDictionary);

            var adapter7 = new StoneStorageDataSetTableAdapters.StorageTableAdapter();
            this.manager.StorageTableAdapter = adapter7;
            adapter7.Fill(DSet.Storage);
            
            var adapter1 = new StoneStorageDataSetTableAdapters.ExpenditureInvoiceDataTableAdapter();
            this.manager.ExpenditureInvoiceDataTableAdapter = adapter1;
            adapter1.Fill(DSet.ExpenditureInvoiceData);
           
            var adapter3 = new StoneStorageDataSetTableAdapters.IncomeInvoiceDataTableAdapter();
            this.manager.IncomeInvoiceDataTableAdapter = adapter3;
            adapter3.Fill(DSet.IncomeInvoiceData);

            var adapter2 = new StoneStorageDataSetTableAdapters.ExpenditureInvoiceItemTableAdapter();
            this.manager.ExpenditureInvoiceItemTableAdapter = adapter2;
            adapter2.Fill(DSet.ExpenditureInvoiceItem);

            var adapter4 = new StoneStorageDataSetTableAdapters.IncomeInvoiceItemTableAdapter();
            this.manager.IncomeInvoiceItemTableAdapter = adapter4;
            adapter4.Fill(DSet.IncomeInvoiceItem);
        }

        public void Save()
        {
            this.manager.UpdateAll(DSet);
        }
    }
}
